#include "helper.h"
#include "world.h"
#include "model/cube.h"
#include "model/fairy.h"
#include "camera.h"

#include <memory>
#include <windows.h>

int main()
{
	GLFWwindow* window = createBasicWindow("Playground");
	
	auto camera = std::shared_ptr<Camera>(new Camera);

	auto fairy = std::shared_ptr<Fairy>(new Fairy());
	fairy->pos.push_back(glm::vec3(0, 0, 0));
	fairy->update();

	auto cube_left = std::shared_ptr<Cube>(new Cube(1));
	auto cube_up = std::shared_ptr<Cube>(new Cube(1));
	auto cube_down = std::shared_ptr<Cube>(new Cube(1));
	auto cube_right = std::shared_ptr<Cube>(new Cube(1));
	auto cube_front = std::shared_ptr<Cube>(new Cube(1));
	auto cube_back = std::shared_ptr<Cube>(new Cube(1));


	cube_left->setPosition(glm::vec3(0,-2,0));
	cube_up->setPosition(glm::vec3(0,0,2));
	cube_down->setPosition(glm::vec3(0,0,-2));
	cube_right->setPosition(glm::vec3(0,2,0));
	cube_front->setPosition(glm::vec3(2,0,0));
	cube_back->setPosition(glm::vec3(-2,0,0));

	World world;
	world.addModel(fairy);
	world.addModel(cube_back);
	world.addModel(cube_front);
	world.addModel(cube_up);
	world.addModel(cube_down);
	world.addModel(cube_left);
	world.addModel(cube_right);
	world.setCamera(camera);

	glEnable(GL_DEPTH_TEST);
	while (!glfwWindowShouldClose(window))
	{
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
		glClearColor(1.0f, 0.737f, 0.737f, 1.0f);

		float t = glfwGetTime();

		camera->setPosition(glm::vec3(8 * glm::cos(t), 8 * glm::sin(t), 8.0f));
		camera->aimAt(glm::vec3(0, 0, 0));

		fairy->setScale(glm::vec3(0.2 * glm::sin(t) + 0.5f));
		fairy->rotate(glm::rotate(glm::mat4(1.0f), glm::radians(5.0f), glm::vec3(0.5f, 1.0f, 0.0f)));
		fairy->setPosition(glm::vec3(0, 0, 0.5 * glm::sin(t)));
		world.render();

		glfwSwapBuffers(window);
		glfwPollEvents();
		Sleep(5);
	}
	return 0;
}